home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MLT_TASK / PIBMDOS / WRITESXY.PAS < prev    next >
Pascal/Delphi Source File  |  1988-03-14  |  14KB  |  183 lines

  1. (*----------------------------------------------------------------------*)
  2. (*          WriteSXY --- Write text string to specified row/column      *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE WriteSXY( S: AnyStr; X: INTEGER; Y: INTEGER; Color: INTEGER );
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Procedure:  WriteSXY                                             *)
  10. (*                                                                      *)
  11. (*     Purpose:    Writes text string at specified row and column       *)
  12. (*                 position on screen.                                  *)
  13. (*                                                                      *)
  14. (*     Calling Sequence:                                                *)
  15. (*                                                                      *)
  16. (*        WriteSXY( S: AnyStr; X: INTEGER; Y: INTEGER; Color: INTEGER );*)
  17. (*                                                                      *)
  18. (*           S      --- String to be written                            *)
  19. (*           X      --- Column position to write string                 *)
  20. (*           Y      --- Column position to write string                 *)
  21. (*           Color  --- Color in which to write string                  *)
  22. (*                                                                      *)
  23. (*     Calls:   None                                                    *)
  24. (*                                                                      *)
  25. (*----------------------------------------------------------------------*)
  26.  
  27. BEGIN (* WriteSXY *)
  28.                                    (* Freeze screen for DoubleDos *)
  29.  
  30.    IF ( MultiTasker = DoubleDos ) THEN
  31.       BEGIN
  32.          TurnOffTimeSharing;
  33.          Get_Screen_Address( Virtual_Screen );
  34.       END;
  35.  
  36. INLINE(
  37.   $1E/                              {         PUSH  DS                            ;Save data segment register}
  38.                                     {;}
  39.                                     {;  Check if we're using BIOS.}
  40.                                     {;}
  41.   $F6/$06/>WRITE_SCREEN_MEMORY/$01/ {         TEST  BYTE [>Write_Screen_Memory],1 ;Direct screen write?}
  42.   $74/$54/                          {         JZ    Bios                          ;No -- go use BIOS}
  43.                                     {;}
  44.                                     {;  Set up for direct screen write.}
  45.                                     {;  Get row position and column positions, and offset in screen buffer.}
  46.                                     {;}
  47.   $C4/$3E/>VIRTUAL_SCREEN/          {         LES   DI,[>Virtual_Screen]          ;Get base address of screen}
  48.   $8B/$4E/<Y/                       {         MOV   CX,[BP+<Y]                    ;CX = Row}
  49.   $49/                              {         DEC   CX                            ;Row to 0..Max_Screen_Line-1 range}
  50.   $A1/>MAX_SCREEN_COL/              {         MOV   AX,[>Max_Screen_Col]          ;Physical screen width}
  51.   $F7/$E1/                          {         MUL   CX                            ;Row * Max_Screen_Col}
  52.   $8B/$5E/<X/                       {         MOV   BX,[BP+<X]                    ;BX = Column}
  53.   $4B/                              {         DEC   BX                            ;Col to 0..Max_Screen_Col-1 range}
  54.   $01/$D8/                          {         ADD   AX,BX                         ;AX = (Row * Max_Screen_Col) + Col}
  55.   $D1/$E0/                          {         SHL   AX,1                          ;Account for attribute bytes}
  56.   $89/$FB/                          {         MOV   BX,DI                         ;Get base offset of screen}
  57.   $01/$C3/                          {         ADD   BX,AX                         ;Add computed offset}
  58.   $89/$DF/                          {         MOV   DI,BX                         ;Move result into DI}
  59.   $A0/>WAIT_FOR_RETRACE/            {         MOV   AL,[<Wait_For_Retrace]        ;Grab this before changing DS}
  60.   $16/                              {         PUSH  SS}
  61.   $1F/                              {         POP   DS}
  62.   $8D/$B6/>S/                       {         LEA   SI,[BP+>S]                    ;DS:SI will point to S[0]}
  63.   $31/$C9/                          {         XOR   CX,CX                         ;Clear CX}
  64.   $8A/$0C/                          {         MOV   CL,[SI]                       ;CL = Length(S)}
  65.   $E3/$27/                          {         JCXZ  Exit1                         ;If string empty, Exit}
  66.   $46/                              {         INC   SI                            ;DS:SI points to S[1]}
  67.   $8A/$66/<COLOR/                   {         MOV   AH,[BP+<Color]                ;AH = Attribute}
  68.   $FC/                              {         CLD                                 ;Set direction to forward}
  69.   $A8/$01/                          {         TEST  AL,1                          ;If we don't wait for retrace, ...}
  70.   $74/$1A/                          {         JZ    Mono                          ; use "Mono" routine}
  71.                                     {;}
  72.                                     {;  Color routine (used only when Wait_For_Retrace is True) **}
  73.                                     {;}
  74.   $BA/>CRT_STATUS/                  {         MOV   DX,>CRT_Status                ;Point DX to CGA status port}
  75.   $AC/                              {GetNext: LODSB                               ;Load next character into AL}
  76.                                     {                                             ; AH already has Attr}
  77.   $89/$C3/                          {         MOV   BX,AX                         ;Store video word in BX}
  78.                                     {;}
  79.   $EC/                              {WaitNoH: IN    AL,DX                         ;Get 6845 status}
  80.   $A8/$01/                          {         TEST  AL,1                          ;Wait for horizontal}
  81.   $75/$FB/                          {         JNZ   WaitNoH                       ; retrace to finish}
  82.                                     {;}
  83.   $FA/                              {         CLI                                 ;Turn off interrupts}
  84.   $EC/                              {WaitH:   IN    AL,DX                         ;Get 6845 status again}
  85.   $A8/$01/                          {         TEST  AL,1                          ;Wait for horizontal retrace}
  86.   $74/$FB/                          {         JZ    WaitH                         ; to start}
  87.                                     {;}
  88.   $89/$D8/                          {Store:   MOV   AX,BX                         ;Restore attribute}
  89.   $AB/                              {         STOSW                               ; and then to screen}
  90.   $FB/                              {         STI                                 ;Allow interrupts}
  91.   $E2/$EC/                          {         LOOP  GetNext                       ;Get next character}
  92.   $E9/$62/$00/                      {         JMP   Exit                          ;Done}
  93.                                     {;}
  94.                                     {;  Mono routine (used whenever Wait_For_Retrace is False) **}
  95.                                     {;}
  96.   $AC/                              {Mono:    LODSB                               ;Load next character into AL}
  97.                                     {                                             ; AH already has Attr}
  98.   $AB/                              {         STOSW                               ;Move video word into place}
  99.   $E2/$FC/                          {         LOOP  Mono                          ;Get next character}
  100.                                     {;}
  101.   $E9/$5B/$00/                      {Exit1:   JMP   Exit                          ;Done}
  102.                                     {;}
  103.                                     {;  Use BIOS to display string (if Write_Screen is False) **}
  104.                                     {;}
  105.   $B4/$03/                          {Bios:    MOV   AH,3                          ;BIOS get cursor position}
  106.   $B7/$00/                          {         MOV   BH,0}
  107.   $55/                              {         PUSH  BP}
  108.   $CD/$10/                          {         INT   $10                           ;Get current cursor position}
  109.   $5D/                              {         POP   BP}
  110.   $52/                              {         PUSH  DX                            ;Save current cursor position}
  111.                                     {;}
  112.   $8A/$76/<Y/                       {         MOV   DH,[BP+<Y]                    ;Get starting row}
  113.   $FE/$CE/                          {         DEC   DH                            ;Drop by one for BIOS}
  114.   $8A/$56/<X/                       {         MOV   DL,[BP+<X]                    ;Get starting column}
  115.   $FE/$CA/                          {         DEC   DL                            ;Drop for indexing}
  116.   $FE/$CA/                          {         DEC   DL                            ;}
  117.   $16/                              {         PUSH  SS}
  118.   $1F/                              {         POP   DS}
  119.   $8D/$B6/>S/                       {         LEA   SI,[BP+>S]                    ;DS:SI will point to S[0]}
  120.   $31/$C9/                          {         XOR   CX,CX                         ;Clear out CX}
  121.   $8A/$0C/                          {         MOV   CL,[SI]                       ;CL = Length(S)}
  122.   $E3/$31/                          {         JCXZ  Bios2                         ;If string empty, Exit}
  123.   $46/                              {         INC   SI                            ;DS:SI points to S[1]}
  124.   $52/                              {         PUSH  DX                            ;Save X and Y}
  125.   $1E/                              {         PUSH  DS                            ;Save string address}
  126.   $56/                              {         PUSH  SI                            ;}
  127.   $FC/                              {         CLD                                 ;Forward direction}
  128.                                     {;}
  129.   $B4/$02/                          {Bios1:   MOV   AH,2                          ;BIOS Position cursor}
  130.   $B7/$00/                          {         MOV   BH,0                          ;Page zero}
  131.   $5E/                              {         POP   SI                            ;Get S address}
  132.   $1F/                              {         POP   DS                            ;}
  133.   $5A/                              {         POP   DX                            ;X and Y}
  134.   $FE/$C2/                          {         INC   DL                            ;X + 1}
  135.   $52/                              {         PUSH  DX                            ;Save X and Y}
  136.   $1E/                              {         PUSH  DS                            ;Save strin address}
  137.   $56/                              {         PUSH  SI}
  138.   $51/                              {         PUSH  CX                            ;Push length}
  139.   $55/                              {         PUSH  BP}
  140.   $CD/$10/                          {         INT   $10                           ;Call BIOS to move to (X,Y)}
  141.   $5D/                              {         POP   BP}
  142.   $59/                              {         POP   CX                            ;Get back length}
  143.   $5E/                              {         POP   SI                            ;Get String address}
  144.   $1F/                              {         POP   DS                            ;}
  145.   $AC/                              {         LODSB                               ;Next character into AL}
  146.   $1E/                              {         PUSH  DS                            ;Save String address}
  147.   $56/                              {         PUSH  SI                            ;}
  148.   $51/                              {         PUSH  CX                            ;Length left to do}
  149.   $55/                              {         PUSH  BP}
  150.   $B4/$09/                          {         MOV   AH,9                          ;BIOS Display character}
  151.   $B7/$00/                          {         MOV   BH,0                          ;Display page zero}
  152.   $8A/$5E/<COLOR/                   {         MOV   BL,[BP+<Color]                ;BL = Attribute}
  153.   $B9/$01/$00/                      {         MOV   CX,1                          ;One character}
  154.   $CD/$10/                          {         INT   $10                           ;Call BIOS}
  155.   $5D/                              {         POP   BP}
  156.   $59/                              {         POP   CX                            ;Get back length}
  157.   $E2/$D7/                          {         LOOP  Bios1}
  158.                                     {;                                            ;Remove stuff left on stack}
  159.   $5E/                              {         POP   SI}
  160.   $1F/                              {         POP   DS}
  161.   $5A/                              {         POP   DX}
  162.                                     {;}
  163.   $5A/                              {Bios2:   POP   DX                            ;Restore previous cursor position}
  164.   $B7/$00/                          {         MOV   BH,0}
  165.   $B4/$02/                          {         MOV   AH,2                          ;BIOS set cursor position}
  166.   $55/                              {         PUSH  BP}
  167.   $CD/$10/                          {         INT   $10}
  168.   $5D/                              {         POP   BP}
  169.                                     {;}
  170.   $1F);                             {Exit:    POP   DS                            ;Restore DS}
  171.  
  172.                                    (* Unfreeze screen in DoubleDos *)
  173.  
  174.    IF ( MultiTasker = DoubleDos ) THEN
  175.       TurnOnTimeSharing
  176.                                    (* Synchronize screen for TopView *)
  177.  
  178.    ELSE IF ( MultiTasker = TopView ) THEN
  179.       IF Write_Screen_Memory THEN
  180.          Sync_Screen( PRED( ( PRED( Y ) * Max_Screen_Col + X ) SHL 1 ) , LENGTH( S ) );
  181.  
  182. END   (* WriteSXY *);
  183.